package org.hq.net;

import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
        // 创建Dispatcher实例
        Dispatcher dispatcher = new Dispatcher();

        // 设置最大并发请求数
        dispatcher.setMaxRequests(64);

        // 设置每个主机的最大并发请求数
        dispatcher.setMaxRequestsPerHost(64);
        // 创建ConnectionPool实例
        ConnectionPool poll = new ConnectionPool(20, 5L, TimeUnit.MINUTES);
        // 创建OkHttpClient实例，并设置自定义的Dispatcher和ConnectionPool
        OkHttpClient client = new OkHttpClient.Builder()
                .dispatcher(dispatcher)
                .connectionPool(poll)
                .connectTimeout(30L, TimeUnit.SECONDS)

                .readTimeout(30L, TimeUnit.SECONDS)
                .writeTimeout(30L,TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .build();

    }
}